// 创建新的HTML模板文件以存放jinja2模板代码
<script type="text/javascript">
    $(document).ready(function() {
        // 构建树结构数据
        const treeData = [
            {% for node in tree_data %}
            {
                id: "{{ node.id }}",
                text: "{{ node.text }}",
                children: [
                    {% for child in node.children %}
                    {
                        id: "{{ child.id }}",
                        text: "{{ child.text }}"
                        {% if child.children %},
                        children: []{% endif %}
                    }{% if not loop.last %},{% endif %}
                    {% endfor %}
                ]
            }{% if not loop.last %},{% endif %}
            {% endfor %}
        ];

        // 初始化jsTree
        $('#jstree-container').jstree({
            'core': {
                'data': treeData,
                'themes': {
                    'responsive': false,
                    'variant': 'large'
                }
            },
            'plugins': ['wholerow']
        });
    });
</script>